package com.huobao.yunying.activitys;

import java.util.List;
import java.util.Map;

import org.xutils.view.annotation.ViewInject;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.huobao.yunying.activitys_store.Act_Store;
import com.huobao.yunying.adapters.Adapter_Zhanqu_detail;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.entity.Zhanqu;
import com.huobao.yunying.entity.ZhanquDetail;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;
import com.huobao.zhangying.R;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class Act_zhanqu_detail extends HuobaoBaseActivity implements OnItemClickListener,OnScrollListener{

	private Adapter_Zhanqu_detail adapter;
	@ViewInject(R.id.listview)
	private ListView listview;
	private Zhanqu zhanqu;
	
	@ViewInject(R.id.btn_totop)
	private ImageView m_TotopBtn;
	
	@ViewInject(R.id.tv_1)
	private TextView tv_empty;

	@Override
	protected int getContentView() {
		// TODO Auto-generated method stub
		return R.layout.layout_zhanqu_detail;
	}

	@Override
	protected String getTitleText() {
		zhanqu = (Zhanqu) getIntent().getSerializableExtra("data");
		return zhanqu.s_name;
	}

	@Override
	protected void init() {
		listview.setOnScrollListener(this);
		listview.setOnItemClickListener(this);
		adapter = new Adapter_Zhanqu_detail(context);
		listview.setAdapter(adapter);
		m_TotopBtn.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				listview.smoothScrollToPosition(0);
			}
		});
		getdata();
	}

	private void getdata() {
		Map<String, String> map = HttpUtil.getParams("app", "promotion", "act", "exhibitorlist", "cateid",
				zhanqu.cateid + "", "zhgid", zhanqu.zhgid + "");
		Http.getInstant().sendRequest(context, map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonObject = JSON.parseObject(result);
				List<ZhanquDetail> list = JSON.parseArray(jsonObject.getString("retval"), ZhanquDetail.class);
				adapter.addAll(list);
				if(list.size() == 0){
					tv_empty.setVisibility(View.VISIBLE);
					listview.setVisibility(View.GONE);
				}else{
					tv_empty.setVisibility(View.GONE);
					listview.setVisibility(View.VISIBLE);
				}
			}

			@Override
			public void onHttpError(String error) {
				// TODO Auto-generated method stub

			}
		});
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Intent intent = new Intent(this, Act_Store.class);
		intent.putExtra("id", adapter.getItem(position).store_id);
		startActivity(intent);
		
	}

	@Override
	public void onScrollStateChanged(AbsListView view, int scrollState) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
		if(firstVisibleItem >= 1 ){
			m_TotopBtn.setVisibility(View.VISIBLE);
		}else {
			m_TotopBtn.setVisibility(View.GONE);
		}
	}

}
